package cn.com.bob.messageboard.utils;

/**
 * @Author Bob
 * @Version：1.0
 */
public class R<E> {
    private Integer code;
    private String msg;

    private E data;

    public R() {
    }


    /**
     * 无数据的成功
     * @param :
     * @return R
     */
    public static R success(){
        R res = new R();
        res.code = 0;
        res.msg = "成功";
        return res;
    }

    /**
     * 有数据的返回
     * @param data:
     * @return R
     */
    public static R success(Object data){
        R res = new R();
        res.code = 0;
        res.msg = "成功";
        res.data = data;
        return res;
    }

    /**
     * 返回指定的错误信息和错误码
     * @param code:
     * @param msg:
     * @return R
     */
    public static R error(Integer code,String msg){
        R res = new R();
        res.code = code;
        res.msg = msg;
        return res;
    }

    /**
     * 通用错误码和指定错误信息
     * @param msg:
     * @return R
     */
    public static R error(String msg){
        R res = new R();
        res.code = 1001;
        res.msg = msg;
        return res;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public E getData() {
        return data;
    }

    public void setData(E data) {
        this.data = data;
    }
}
